<?php

namespace app\model;


class UserVideo extends Model
{
    public function __construct($db)
    {
        parent::__construct($db, "sticker");
        $this->type_sub="type_sub";//话题表
        $this->sticker="sticker";//贴纸表
        $this->sticker_type="sticker_type";//贴纸分类表
        $this->music_type="music_type";//音效分类表
        $this->music="music";//音效表
        $this->user_material="user_material";//用户素材表
    }

    /**
     * 查询话题
     */
    public function type_subs(){
        $this->db->select("id,sub_type,sub_title");
        $this->db->from($this->type_sub);
        $this->db->where(["del2" => 2,"online" =>2,"is_other !=" =>999999999]);
        $this->db->order_by(["sort" => "asc"]);
        $query = $this->db->get();
        $datas = $query->all();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 查询贴纸分类
     */
    public function sticker_type(){
        $this->db->select("id,sticker_type_name,select_icon,no_select_icon");
        $this->db->from($this->sticker_type);
        $this->db->where(["status" => 2]);
        $this->db->order_by(["time_tmp" => "desc"]);
        $query = $this->db->get();
        $datas = $query->all();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 查询贴纸
     */
    public function sticker($sticker_id,$page,$pageSize){
        $this->db->select("id,icon,pics,sticker_name");
        $this->db->from($this->sticker);
        $this->db->where(["del4" => 2,"sticker_id"=>$sticker_id]);
        $this->db->order_by(["sorts" => "desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query = $this->db->get();
        $datas = $query->all();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 查询音效分类
     */
    public function music_type(){
        $this->db->select("id,music_type_name,music_type_icon,no_music_type_icon");
        $this->db->from($this->music_type);
        $this->db->where(["music_type_status" => 2]);
        $this->db->order_by(["music_tmp" => "desc"]);
        $query = $this->db->get();
        $datas = $query->all();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 查询音效
     */
    public function music($music_id,$page,$pageSize){
        $this->db->select("id,music_name,music_url,music_type_id");
        $this->db->from($this->music);
        $this->db->where(["music_status" => 2,"music_type_id"=>$music_id]);
        $this->db->order_by(["music_time_tmp" => "desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query = $this->db->get();
        $datas = $query->all();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 添加用户素材
     */
    public function add_material($data){
         $this->db->insert($this->user_material,$data);
        return $this->db->insert_id();
    }

    /**
     * 添加用户素材
     */
    public function update_material($data,$job_id){
        return $this->db->update($this->user_material,$data,['material_id'=>$job_id]);
    }

    /**
     * 添加用户素材
     */
    public function update_materials($data,$job_id){
        return $this->db->update($this->user_material,$data,['id'=>$job_id]);
    }

}